<template>
  <div class="patient-number-date">
    <div class="patient-number-date-inside">
      <div class="header">
        <div class="left item">
          <img
              alt="左侧"
              src="@/components/assets/images/design/1-12.webp"
          />
        </div>
        <div class="middle item">患者预约信息</div>
        <div class="right item">
          <img
              alt="右侧"
              src="@/components/assets/images/design/1-12.webp"
          />
        </div>
      </div>
      <el-row class="patient-number-area">
        <template v-if="PreAppointReg.state">
          <template v-for="item in [PreAppointReg.result]">
            <el-col :span="24">
              <el-row class="item-childs item-top">
                <el-col :span="24">
                  <div class="patient-number-item">
                    <div class="left">
                      日期：
                    </div>
                    <div class="right">
                      {{ item?.medDate }}&nbsp;{{ parseInt(item?.medAmPm) === 1 ? "上午" : " 下午" }}
                    </div>
                  </div>
                </el-col>
                <el-col :span="24">
                  <div class="patient-number-item">
                    <div class="left">
                      科室：
                    </div>
                    <div class="right">
                      {{ item?.deptName }}
                    </div>
                  </div>
                </el-col>
                <el-col :span="24">
                  <div class="patient-number-item">
                    <div class="left">
                      医生：
                    </div>
                    <div class="right">
                      {{ item?.doctName }}
                    </div>
                  </div>
                </el-col>
                <el-col :span="12">
                  <div class="patient-number-item item-24">
                    <div class="left">
                      个人支付：
                    </div>
                    <div class="right">
                      ¥{{ (item?.selfFee) / 100 || '0.0' }}元
                    </div>
                  </div>
                </el-col>
                <el-col :span="12">
                  <div class="patient-number-item item-24">
                    <div class="left">
                      医保报销：
                    </div>
                    <div class="right">
                      ¥{{ (item?.insurFee) / 100 || '0.0' }}元
                    </div>
                  </div>
                </el-col>
              </el-row>
            </el-col>
            <el-col :span="24">
              <div class="item-childs item-middle">
                <div class="left">
                  挂号费：¥{{ item?.regFee || '0.0' }}
                </div>
                <div class="right" @click="handleClick(item)">
                  确定
                </div>
              </div>
            </el-col>
          </template>
        </template>
        <template v-else>
          <el-empty description="暂无数据"></el-empty>
        </template>
      </el-row>
    </div>
  </div>
</template>

<script>
import {buildParentApi} from "@/utils/designer/util";
import {v4 as uuid} from "uuid";
import {Toast} from 'vant';

let buildParent = buildParentApi();
export default {
  name: 'RegisterInfo',

  componentName: "RegisterInfo",

  components: {Toast},

  data() {
    return {}
  },

  computed: {

    // 预结算信息
    PreAppointReg() {
      let bizInfo = this.$store.getters['DRCbiz/getBizInfo'];
      if (parseInt(bizInfo.id) === 1) {
        let resultInfo = Object();
        let currScheduleInfo = this.$lodash.cloneDeep(this.$store.getters['DRCbiz/getCurrentScheduleInfo']);
        let currTimeRangeInfo = this.$store.getters['DRCbiz/getCurrTimeRangeInfo'];
        let dateInfo = this.$store.getters['DRCbiz/getDateInfo'];
        let {result} = this.$store.getters['DRCbiz/getPatientInfo'];
        Reflect.set(currScheduleInfo, 'patientId', result?.patientId);
        Reflect.set(currScheduleInfo, 'medDate', dateInfo?.dateInfo);
        Reflect.set(currScheduleInfo, 'appoNo', currTimeRangeInfo?.appoNo);
        Reflect.set(currScheduleInfo, 'restNum', currTimeRangeInfo?.restNum);
        Reflect.set(currScheduleInfo, 'medbegtime', currTimeRangeInfo?.medbegtime);
        Reflect.set(currScheduleInfo, 'medendtime', currTimeRangeInfo?.medendtime);
        Reflect.set(resultInfo, 'state', true);
        Reflect.set(resultInfo, 'result', currScheduleInfo)
        return resultInfo
      } else {
        return this.$store.getters['DRCbiz/getAppointRegInfo']
      }
    },

    PTypeInfo() {
      return this.$store.getters['DRCbiz/getOPTypeInfo']
    },

    bizInfo() {
      return this.$store.getters['DRCbiz/getBizInfo']
    },

    deptInfo() {
      return this.$store.getters['DRCbiz/getDeptInfo']
    },

    cardTypeInfo() {
      return this.$store.getters['DRCbiz/getCardTypeInfo']
    },

    patientInfo() {
      return this.$store.getters['DRCbiz/getPatientInfo']
    },

    DrScheduleList() {
      return this.$store.getters['DRCbiz/getDrScheduleList']
    },

    currentScheduleInfo(){
      return this.$store.getters['DRCbiz/getCurrentScheduleInfo']
    },

    currTimeRangeInfo(){
      return this.$store.getters['DRCbiz/getCurrTimeRangeInfo']
    }

  },

  mounted() {
  },

  methods: {

    handleClick(row) {
      let bizInfo = (this.bizInfo);
      let type = parseInt(bizInfo.id)
      // 预约(1)无需支付费用 挂号(2)和取号(3)要支付费用
      switch (type) {
        case 1:
          this.handleAppointReg(row)
          break;
        case 2:
          if (parseInt(row?.selfFee) === 0) {
            this.handleAppointReg(row)
          } else {
            Toast({
              message: `很抱歉，因为设计自费缴费，请去人工窗口挂号或取号`,
              position: 'bottom',
              type: 'fail',
              forbidClick: true,
              duration: 3000
            });
          }
          break;
      }
    },
    // 付款
    handleAppointReg(row) {
      let params = Object();
      let paramInfo = Object();
      let PTypeInfo = (this.PTypeInfo);
      let bizInfo = (this.bizInfo);
      let patientInfo = (this.patientInfo)
      let cardTypeInfo = (this.cardTypeInfo);
      let hospAreaInfo = (this.hospAreaInfo);
      let currScheduleInfo = (this.currentScheduleInfo);
      let currTimeRangeInfo= (this.currTimeRangeInfo);
      let {state, result} = (this.DrScheduleList);
      let devInfo = JSON.parse(localStorage.getItem('deviceInfo'));
      Reflect.set(paramInfo, 'deviceIp', (devInfo?.screenIp));
      Reflect.set(paramInfo, 'flowId', uuid());
      Reflect.set(paramInfo, 'timestamp', this.$day().valueOf());
      Reflect.set(paramInfo, 'terminalNo', (devInfo?.screenId));
      Reflect.set(paramInfo, 'method', 'AppointReg');
      Reflect.set(paramInfo, 'hospCode', (hospAreaInfo?.id) || 1);
      // 电子医保凭证
      if (parseInt(cardTypeInfo?.id) === 29) {
        Reflect.set(paramInfo, 'cardNo', (cardTypeInfo?.cardInfo));
        Reflect.set(paramInfo, 'cardHardInfo', (cardTypeInfo?.cardInfo));
      } else {
        Reflect.set(paramInfo, 'cardNo', (cardTypeInfo?.cardNo));
        Reflect.set(paramInfo, 'cardHardInfo', (cardTypeInfo?.cardInfo));
      }

      if (patientInfo.state) {
        Reflect.set(paramInfo, 'patientId', (patientInfo.result.patientId));
      } else {
        Reflect.set(paramInfo, 'patientId', '');
      }
      Reflect.set(paramInfo, 'cardType', (cardTypeInfo.id));
      Reflect.set(paramInfo, 'regMode', (bizInfo.id));
      Reflect.set(paramInfo, 'regType', (PTypeInfo.level));
      Reflect.set(paramInfo, 'medDate', (row?.medDate));
      Reflect.set(paramInfo, 'medAmPm', (row?.medAmPm))
      Reflect.set(paramInfo, 'medTime', `${(currTimeRangeInfo?.medbegtime)}-${(currTimeRangeInfo?.medendtime)}}`);
      if (state) {
        Reflect.set(paramInfo, 'deptCode', (result?.deptCode) ||(row?.deptCode));
        Reflect.set(paramInfo, 'scheduleId', (result?.scheduleId));
      } else {
        Reflect.set(paramInfo, 'deptCode', (row?.deptCode));
        Reflect.set(paramInfo, 'scheduleId', null);
      }
      Reflect.set(paramInfo, 'cash', (row?.selfFee) || 0);
      Reflect.set(paramInfo, 'ybCardNo', uuid());
      Reflect.set(paramInfo, 'isZj', (row?.selfFee) || 0);
      Reflect.set(paramInfo, 'TOKEN', uuid());
      Reflect.set(paramInfo, 'deviceVersion', uuid());
      Reflect.set(paramInfo, 'deviceInfo', uuid());
      Reflect.set(paramInfo, 'operId', (devInfo?.screenId) || '0');
      Reflect.set(paramInfo, 'sourceCode', 2);
      Reflect.set(paramInfo, 'doctCode', (currScheduleInfo?.doctCode) || '');
      Reflect.set(paramInfo, 'appoNo', (currTimeRangeInfo?.appoNo) || '');
      // tradeMode:结算方式
      Reflect.set(paramInfo, 'tradeMode', "CA");
      Reflect.set(paramInfo, 'tradeTime', this.$day().format('YYYY-MM-DD HH:mm:ss'));
      Reflect.set(paramInfo, 'insurFee', (row?.insurFee) || '');
      Reflect.set(paramInfo, 'insurFeeinfo', (row?.insurFeeinfo) || '');
      Reflect.set(paramInfo, 'receiptNo', (row?.receiptNo) || '');
      Reflect.set(params, 'Request', paramInfo);
      let paramsInfo = this.$x2js.js2xml(params);
      console.log(params);
      console.log(paramsInfo);
      buildParent.executeParentMethod('axiosRep', paramsInfo, 'AppointReg');
    }
  },
}

</script>

<style scoped lang="scss">
@import "assets/style";
</style>